------------------ fgui require start ------------------
------------------  fgui require end  ------------------
local Flag = require 'View/UIGuild/Skin/FlagSkin'; 
local UIGuildFlagSkin = Class("UIGuildFlagSkin");

function UIGuildFlagSkin:ctor(com,selFlagIdx)
    self.seledFlagIndex = selFlagIdx;
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.btn_blackbackground.onClick:Add(self.onTouch_Btn_blackbackground,self);
    self.btn_cancel.onClick:Add(self.onTouch_Btn_cancel,self);
    self.btn_determine.onClick:Add(self.onTouch_Btn_determine,self);
    self.list_flag.onClickItem:Add(self.onClickItem_List_flag,self);
    self.list_flag.itemRenderer = function(index,obj) self:onRender_List_flagItem(index,obj); end;
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function UIGuildFlagSkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.btn_blackbackground = com:GetChild("Btn_blackbackground");
    self.btn_cancel = com:GetChild("Btn_cancel");
    self.btn_determine = com:GetChild("Btn_determine");
    self.text_close = com:GetChild("Text_close");
    self.text_leavingamessage = com:GetChild("Text_leavingamessage");
    self.list_flag = com:GetChild("List_flag");
    ------------------  fgui变量绑定end  ------------------
end

function UIGuildFlagSkin:init() 
    self.seledFlag = nil;
    self.listItems = {}
    self.text_leavingamessage.text = getLanguage("GuildInvestment_1085")
    self.list_flag.numItems = #logicMgr.GuildManager.db_guildlogo;
end

function UIGuildFlagSkin:setCloseCallback(func,target)
    self.btn_blackbackground.onClick:Add(func,target);
    self.btn_cancel.onClick:Add(func,target);
    self.btn_determine.onClick:Add(func,target);
end

function UIGuildFlagSkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.btn_blackbackground.onClick:Clear();
    self.btn_cancel.onClick:Clear();
    self.btn_determine.onClick:Clear();
    self.list_flag.onClickItem:Clear();
    self.list_flag.itemRenderer = nil;
    ------------------  fgui事件移除end  ------------------
end

function UIGuildFlagSkin:onTouch_Btn_blackbackground(obj) end

function UIGuildFlagSkin:onTouch_Btn_cancel(obj) end

function UIGuildFlagSkin:onTouch_Btn_determine(obj) 
    if self.seledFlag then
        self.seledFlagIndex = self.seledFlag.idx;
    end
end

function UIGuildFlagSkin:onClickItem_List_flag(context)
    local item = self.listItems[context.data];
    if item:isLocked() then return end;
    if self.seledFlag then
        self.seledFlag:doSeled(false);
    end
    item:doSeled(true);
    self.seledFlag = item;
end

function UIGuildFlagSkin:onRender_List_flagItem(index,obj)
    local item = self.listItems[obj];
    if item == nil then
        item = Flag.New(obj);
        self.listItems[obj] = item;
    end
    item:onRender(logicMgr.GuildManager.db_guildlogo[index+1],self.seledFlagIndex);
    if item:isSeled() then
        self.seledFlag = item;
    end
end

------------------  ↑ fgui事件句柄 ↑  ------------------

function UIGuildFlagSkin:beforeDestroy() 
    self.listItems = {}
end

return UIGuildFlagSkin;
